
package collections.my;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ReverseCollectionExample
{

	public static void main(String[] args)
	{
		//simpleRotateCollection();
		hardRotateCollection();
	}

	private static void simpleRotateCollection()
	{
		List<String> list = new ArrayList<String>(10);
		list.add("1");
		list.add("2");
		list.add("3");
		list.add("4");
		list.add("5");
		
		System.out.println("coll : " + list);
		
		Collections.reverse(list);
		System.out.println("coll : " + list);
	}

	private static void hardRotateCollection()
	{
		List<String> list = new ArrayList<String>();
		list.add("1");
		list.add("2");
		list.add("3");
		list.add("4");
		list.add("5");
		System.out.println("coll : " + list);
		
		for (int index = 0; index < list.size()/2; index++)
		{
			String leftElement = list.get(index); 
			String rightElement = list.get(list.size()- index - 1);
			
			list.set(index, rightElement);
			list.set(list.size()- index - 1, leftElement);
		}
		
		
		System.out.println("coll : " + list);
	}
	
}
